package com.xiaoqiang.git.hellojavaserialportnew.controller;

import com.xiaoqiang.git.hellojavaserialportnew.config.SerialConfig;
import com.xiaoqiang.git.hellojavaserialportnew.model.Reply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@Api(tags = "串口 控制层")
@RestController
@RequestMapping("serial")
public class SerialController {

    @ApiOperation("获取串口列表")
    @GetMapping
    public Reply list(){
        return Reply.success(SerialConfig.getSerials());
    }

    @ApiOperation("串口连接")
    @PostMapping
    public Reply connect(String portName, int baudRate){
        return SerialConfig.openSerialPort(portName, baudRate);
    }

    @ApiOperation("串口发送数据")
    @PutMapping
    public Reply sendData(String portName,String message){
        return SerialConfig.sendData(portName,message);
    }

    @ApiOperation("串口关闭")
    @DeleteMapping
    public Reply close(String portName){
        return SerialConfig.closeSerialPort(portName);
    }
}
